-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use crossterm cursor when terminal loses focus #6858
Use crossterm cursor when terminal loses focus #6858
Conversation
52ac7a2
to
a3e7b9a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Named colors (cyan, yellow, red, etc.) are defined by the terminal (for example https://sw.kovidgoyal.net/kitty/conf/#the-color-table) and there's no way to query their value from a terminal application. I don't think we should be blending colors anyways though: all colors should be written out explicitly in a theme
Hmm this is probably a better idea than what I had: I simply hid the cursor. But that makes it a bit confusing when the window is out of focus since no other editor would behave that way |
a3e7b9a
to
c92da2f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. It would be nice if you could define an unfocused color for the default theme tough (the rest of the themes can be changed by their author but it's nice if the default works)
Yeah I am trying to but I cannot figure out the default theme keys. The cursor has different colors depending on if its on a char or a whitespace and cannot figure out where this behavior is defined the theme.toml. With my current impl. the cursor will always have the same color when out of focus. |
c92da2f
to
71cf439
Compare
That's default theme uses |
But this creates the problem that I need to chose a color that works well for all colors the cursor can have. This is kinda tricky. I will try to find a good one. |
71cf439
to
ca75b08
Compare
I marked this as ready for review as we are already reviewing. If you feel this is not ready yet feel free to change the status again. There seem to be some problems with the default theme and lints that need fixing (see CI) |
0ca9c95
to
d41446f
Compare
I think this is ready. I updated the catppuccin mocha theme to support this feature aswell. The only thing that could need work is the default theme. You guys might wanna check it out and maybe even try if you like other colors more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good, just a minor comment. We'll also want to get @archseer's review since this touches the default theme
d41446f
to
a29d11b
Compare
a29d11b
to
c8defc0
Compare
bb46d07
to
a9d5df1
Compare
This is not ready yet. I think we should go back to draft. I want to try this idea:
However I am a bit lost in the code base. I was yet not able to find the correct place to overwrite the cursor. I found how to overwrite the cursor when the crossterm cursor is in use but I could not figure out how to switch between crossterm cursor and custom cursor. Unfortunately I didn't had much time recently. Maybe you have a hint for me? |
helix/helix-term/src/application.rs Lines 1152 to 1156 in 8c68074
|
a9d5df1
to
2087875
Compare
I finally managed to impl. the behavior. It seems to work flawless. The only point left to discuss: Should we also do something about secondary cursors? Currently only the main cursor is changing when losing focus. I think for me thats ok. What is your opinion? |
I think we can leave secondary cursors as-is. We can't make them bars (we just fill in a background to make them look like blocks normally) like the primary cursor. We could add theming for them when unfocused like the original change in this PR if the bar cursor isn't clear enough. That could probably be a follow-up though |
Yeah I think you are right that it could be a follow-up after using this for some time and see if it would be helpful. With that I think the PR is ready. Should I update the initial PR message? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a minor nit about a comment.
I like this behavior - it looks nice to me on Kitty for single panes and splits
Use crossterm cursor in the editor when the terminal is out of focus to achieve consistent out-of-focus cursor behaviour
2087875
to
3aff043
Compare
Use crossterm cursor in the editor when the terminal is out of focus to achieve consistent out-of-focus cursor behaviour
Use crossterm cursor in the editor when the terminal is out of focus to achieve consistent out-of-focus cursor behaviour
Use crossterm cursor in the editor when the terminal is out of focus to achieve consistent out-of-focus cursor behaviour
Use crossterm cursor in the editor when the terminal is out of focus to achieve consistent out-of-focus cursor behaviour
All but the documents block cursor change their shape to a box outline if the terminal loses focus. I am missing that feature because (depending on your window manager) it can be hard to tell which editor has focus if you have multiple open at the same time. Because the custom rendered block cursor is just the background color of the respective char it is no possible to achieve the same behavior (display as outline).
Therefore I created a proof of concept for the custom block cursor to change its color when the terminal window loses focus.
If the theme does not define a color for the unfocused cursor (e.g.
ui.cursor.primary.unfocused
) it should calculate the color by faking transparency of the cursor. Therefore it tries to get the background color and the cursor color and mix them.Currently I have 2 main problems with the color calculation:
The current implementation works well with some themes, e.g. gruvbox, catpuccin_*, emacs.
Another questions that should be discussed: